package com.bsj.power.pls.web;

import com.bsj.power.common.config.global.JsonResult;
import com.bsj.power.common.def.dto.path.PathDTO;
import com.bsj.power.common.def.dto.tree.TreeDTO;
import com.bsj.power.common.def.vo.pls.PathVO;
import com.bsj.power.common.def.vo.sys.menu.MenuTreeVO;
import com.bsj.power.common.def.vo.tree.TreeStructureVO;
import com.bsj.power.common.def.vo.tree.TreeVO;
import com.bsj.power.pls.service.TreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LiJiaXin
 * @version 1.0.0
 * @description TreeController
 * @time 2024/10/9 11:38
 */
@RestController
@RequestMapping("/tree")
public class TreeController {

    @Autowired
    private TreeService treeService;

    /**
     * 添加
     *
     * @param treeDTO
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/10/9 14:00
     */
    @PostMapping("/add")
    public JsonResult add(@Validated @RequestBody TreeDTO treeDTO) {
        return treeService.addTree(treeDTO);
    }

    /**
     * 删除
     *
     * @param treeId
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/10/9 14:00
     */
    @PostMapping("/delete/{treeId}")
    public JsonResult delete(@PathVariable("treeId") Integer treeId) {
        return treeService.deleteTree(treeId);
    }

    /**
     * 修改
     *
     * @param treeDTO
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/10/9 14:00
     */
    @PostMapping("/update")
    public JsonResult update(@RequestBody @Validated TreeDTO treeDTO) {
        return treeService.updateTree(treeDTO);
    }

    /**
     * 查询单个
     *
     * @param treeId
     * @return com.bsj.power.common.config.global.JsonResult<com.bsj.power.common.def.vo.tree.TreeVO>
     * @author ljx
     * @time 2024/10/9 14:00
     */
    @GetMapping("/getById/{treeId}")
    public JsonResult<TreeVO> getById(@PathVariable("treeId") Integer treeId) {
        return JsonResult.success(treeService.getTreeById(treeId));
    }

    /**
     * 树结构
     *
     * @return com.bsj.power.common.config.global.JsonResult<java.util.List<com.bsj.power.common.def.vo.tree.TreeStructureVO>>
     * @author ljx
     * @time 2024/10/9 14:01
     */
    @GetMapping("/tree")
    public JsonResult<List<TreeStructureVO>> tree() {
        return JsonResult.success(treeService.getTreeStructure());
    }

}
